package com.cooba.views;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import com.cooba.R;
import com.cooba.pullTorefresh.PullToRefreshListView;

/**
 * Created by Administrator on 2016/7/15.
 */
public class EmptyViewHelper {
    private PullToRefreshListView mListView;
    private View emptyView;
    private Context mContext;
    private String mEmptyText;
    private TextView mTextView;

    public EmptyViewHelper(PullToRefreshListView listView) {
        mListView = listView;
        mContext = listView.getContext();
        initEmptyView();
    }

    public EmptyViewHelper(PullToRefreshListView listView, String text) {
        mListView = listView;
        mContext = listView.getContext();
        mEmptyText = text;
        initEmptyView();
    }

    private void initEmptyView() {
        emptyView = View.inflate(mContext, R.layout.empty_view, null);
        ((ViewGroup)mListView.getParent()).addView(emptyView);
        mListView.getRefreshableView().setEmptyView(emptyView);
        if (!TextUtils.isEmpty(mEmptyText)) {
            ((TextView)emptyView.findViewById(R.id.empty)).setText(mEmptyText);
        }
    }
}
